//
//  UIBarButtonItem+Extension.swift
//  WeiboProject
//
//  Created by yanli on 16/7/9.
//  Copyright © 2016年 mountainPassCell. All rights reserved.
//

import UIKit

//  分类不能提供指定构造函数
extension UIBarButtonItem {
    //  提供便利构造函数创建UIBarButtonItem
    convenience init(title: String,target: AnyObject?, action: Selector) {
        //初始化
        self.init()
        //创建 Btn
        let btn = UIButton()
        
        //添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        //设置文字和颜色
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        //设置字体大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        btn.sizeToFit()
        
        // 设置 customView
        customView = btn
    }
    
}